<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Title</title>
</head>
<body>
<form action="#" method="post">
  <p>
    <!-- requeird必填字段-->
    <span>银行账号：</span>
    <input type="text" class="inputsgl" required />

  </p >
  <!-- <button type="button" onclick="Trim()">提交</button>-->
</form>
<script>
  window.onload = function () {
    var BA = document.getElementsByClassName("inputsgl")
    BA.onkeypress = function () {
      if (event.keyCode == 32) {
        // alert('不能输入空格')
        event.returnValue = false
      }
    }
    BA.onkeyup = function () {
      // alert('不能输入空格')
      this.value = this.value.replace(/[, ]/g, '')
    }
  }
</script>
</body>
</html>